﻿using System;
using System.ComponentModel;
using WindowsAPI.Hooks;

namespace WindowsAPI
{
    [Serializable]
    [/*DefaultEvent("OnKeyDown"),*/ DefaultProperty("Enable")]
    //[ToolboxBitmap(typeof(KeyboardComponent))]
    public partial class CBTHookComponent : Component, INotifyPropertyChanged
    {

        /* --------------------------------------------------------------------------------------------- */

        #region События

        private event PropertyChangedEventHandler e_PropertyChanged;
        [System.ComponentModel.PropertyTab("test")]
        //[EditorBrowsable(EditorBrowsableState.Never)]
        [Description("Событие возникает при изменении свойства объекта")]
        public event PropertyChangedEventHandler PropertyChanged
        {
            add { e_PropertyChanged += value; }
            remove { e_PropertyChanged -= value; }
        }
        private void Invoke_PropertyChanged(string PropertyName)
        {
            var lv_Handlers = e_PropertyChanged;
            if(lv_Handlers != null)
                e_PropertyChanged.Invoke(this, new PropertyChangedEventArgs(PropertyName));
        }

        /// <summary>Событие возникает при включении и выключении объекта</summary>
        [Category("State")]
        [Description("Событие возникает при включении и выключении объекта")]
        public event EventHandler EnableChanged;
        protected virtual void Invoke_OnEnableChanged(EventArgs Args)
        {
            var lv_Handlers = EnableChanged;
            if(lv_Handlers != null)
                lv_Handlers.Invoke(this, Args);
            Invoke_PropertyChanged("Enable");
        }
        private void Invoke_OnEnableChanged() { Invoke_OnEnableChanged(EventArgs.Empty); }

        #endregion

        /* --------------------------------------------------------------------------------------------- */

        #region Поля

        private readonly CBTHook f_Hook = new CBTHook();

        #endregion

        /* --------------------------------------------------------------------------------------------- */

        #region Свойства

        /// <summary>Состояние активности объекта</summary>
        [Category("State"), Description("Состояние активности объекта"), DefaultValue(false)]
        public bool Enable
        {
            get { return f_Hook.Enable; }
            set
            {
                if(Enable == value) return;
                f_Hook.Enable = value;
                Invoke_OnEnableChanged();
            }
        }

        #endregion

        /* --------------------------------------------------------------------------------------------- */

        public CBTHookComponent() : this(null) { }

        public CBTHookComponent(IContainer container)
        {
            if(container != null) container.Add(this);
            InitializeComponent();
            f_Hook.Event += Hook_Event;
        }

        /* --------------------------------------------------------------------------------------------- */

        private void Hook_Event(object sender, HookEventArgs e)
        {

        }

        /* --------------------------------------------------------------------------------------------- */
    }
}
